package com.zf.enums;

import java.util.Arrays;

public class EnumTest {
    public static void main(String[] args) {

        System.out.println("枚举属性和方法调用：");
        System.out.println(SimpleEnum.RED);
        System.out.println(SimpleEnum.RED.name()); // 枚举值的名字 RED，是父类 java.lang.Enum 的方法
        System.out.println(SimpleEnum.RED.ordinal()); //枚举值在枚举类中定义的顺序：从0开始，是父类 java.lang.Enum 的方法
        System.out.println(IncludeFieldEnum.DOG);
        System.out.println(IncludeFieldEnum.DOG.getName());
        System.out.println(IncludeFieldEnum.DOG.getIndex());
        System.out.println(IncludeFieldEnum.DOG.ordinal());
        System.out.println(IncludeFieldEnum.sheep.ordinal());
        System.out.println(Arrays.toString(IncludeFieldEnum.values())); // 获取该枚举类中的所有枚举值
        System.out.println(Arrays.toString(IncludeFieldEnum.DOG.values())); // 同 IncludeFieldEnum.values() 方法
        System.out.println(IncludeFieldEnum.DOG.getDeclaringClass());
        System.out.println(IncludeFieldEnum.DOG == IncludeFieldEnum.CAT);


        System.out.println("枚举实现方法：");
        ImplementInterfaceEnum.ONE.printName();
        ImplementInterfaceEnum.ONE.printOrdinal();
        ImplementInterfaceEnum.ONE.printAge();

        ImplementInterfaceEnum.TWO.printName();
        ImplementInterfaceEnum.TWO.printOrdinal();
        ImplementInterfaceEnum.TWO.printAge();


        System.out.println("枚举的Switch: ");
        IncludeFieldEnum includeFieldEnum = IncludeFieldEnum.CAT;
        switch (includeFieldEnum) {
            case sheep:
                System.out.println("sheep");
                break;
            case CAT:
                System.out.println(Arrays.toString(includeFieldEnum.values()));
                break;
            case DOG:
                System.out.println("dog");
                break;
            default:
                System.out.println("default");
        }
    }
}
